<div class="waypoint container contact">
    <div class="row">
        <div class="col-md-12">
            <h2 class="page-title">Empresas</h2>
        </div>

        <div class="col-md-12">

            <div id="search">
                <form action="<?php echo $this->url(array('controller' => 'evaluation', 'action' => 'index')) ?>" method="get" id="company-search-form">
                    <div class="col-md-4"><input type="text" name="q" placeholder="Empresa" value="<?php if (isset($_GET['q'])) echo $_GET['q']; ?>" /></div>
                    <div class="col-md-3"><input type="text" name="loc" placeholder="Local" value="<?php if (isset($_GET['loc'])) echo $_GET['loc']; ?>" /></div>
                    <div class="col-md-3">
                        <select id="cat" name="cat">
                            <option value="all">Todas Empresas</option>
                            <?php 
                                foreach ($this->categories AS $key => $value) {
                                    if (isset($_GET['cat']) && ($_GET['cat'] == $key)) {
                                        echo '<option value="'.$key.'" selected>'. $value .'</option>';
                                    } else {
                                        echo '<option value="'.$key.'">'. $value .'</option>';
                                    }
                                } 
                            ?>
                        </select>
                    </div>
                    <div class="col-md-1"><input name="submit" type="submit" class="btn btn-large blue-color" id="submit" value="Procurar" /></div>
                </form>
            </div><!-- end #search -->

        </div><!-- end .col-md-12 -->
    </div><!-- end .row -->
    <br /><br />
    <div class="row">
        
        <div class="col-md-12">
            <!-- -->
            <?php 
            if (count($this->companies) <= 0) {
               echo '<div style="width: 100%; text-align: center" class="row">Nenhum registro encontrado. Tente uma busca diferente ou cadastre sua empresa.</div>';
            } else {
                foreach ($this->companies AS $company) {
                    if ($company['logo'] == '') {
                        $imgLogo = '/img/default-logo.jpg';
                    }else {
                        $imgLogo = $company['logo'];
                    }
                    switch ($company['evaluations']) {
                        case 1:
                            $evaluations = $company['evaluations'] .' Avaliação';
                            break;
                        default:
                            $evaluations = $company['evaluations'] .' Avaliações';
                            break;
                    }
                    echo '
                        <div class="col-md-6" style="padding-top: 4em; padding-bottom: 1em;">
                            <div class="row">
                                <div class="col-md-3">
                                    <a href="'. $this->url(array('controller' => 'evaluation', 'action' => 'detalhes', 'company' => $company['friendly_name'])) .'">
                                    <img class="img-thumbnail" src="'. $this->baseUrl() . $imgLogo .'">
                                    </a>
                                </div>
                                <div class="col-md-8"> 
                                    <div class="row company-list-title">
                                        <a href="'. $this->url(array('controller' => 'evaluation', 'action' => 'detalhes', 'company' => $company['friendly_name'])) .'"> '.$company['name'].' </a>
                                    </div>
                                   <div class="row"> 
                                         <span class="fa fa-inbox" data-toggle="tooltip" title="Categoria"></span> '. $company['category'] .'
                                    </div>
                                    <div class="row">
                                        <div class="rate" data-score="'. $company['star_rate'] .'" style="margin-top: 10px"> </div>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                               <div class="col-md-3">
                                    <span style="margin-left: 8px" class="fa fa-comments"></span> '. $evaluations .'
                                </div>
                            </div>
                        </div>';
                }
            }
            ?>
        </div><!-- end .col-md-12 -->
    </div><!-- end .row -->
    
    <div class="row">
        <div class="col-md-12" style="width: 100%; text-align: center;"><a href="<?php echo $this->url(array('controller' => 'evaluation', 'action' => 'nova-empresa')) ?>" class="btn btn-large btn-success" style="width: 55%; text-align: center; text-transform: uppercase; font-weight: bold; margin-top: 4em;">Não encontrou sua empresa? Cadastre ela agora.</a></div>
    </div>
    
    <div class="row">
        <div class="col-md-12" style="width: 100%; text-align: center;">
            <?php 
                if ($this->pages > 1) {
                    if (isset($_GET['cat'])){
                        $filter = '?q='.$_GET['q'].'&loc='.$_GET['loc'].'&cat='.$_GET['cat'];
                    } else {
                        $filter = '';
                    }
                    echo '<ul class="pagination pagination-lg" style="margin-top: 40px">';
                    for($i=1; $i <= $this->pages; $i++) {
                        if ($this->pageAtual == $i) {
                            echo '<li class="active"><a href="'.$this->url(array('controller' => 'evaluation', 'action' => 'index', 'page' => $i)).$filter.'"> '.$i.' </a></li>';
                        } else {
                            echo '<li><a href="'.$this->url(array('controller' => 'evaluation', 'action' => 'index', 'page' => $i)).$filter.'"> '.$i.' </a></li>';
                        }
                    }
                    echo '</ul>';  
                }
            ?>
        </div>
    </div>
</div><!-- end section -->
<br />
<script type="text/javascript">
$( document ).ready(function() {
    $(".rate").raty({ path: '<?php echo $this->baseUrl() . "/img/stars-medium/" ?>', size: 44, readOnly: true, halfShow : true, score: function() {return $(this).attr('data-score');}});
    $('span').tooltip();
});
</script>